/*
 * Order.h
 *
 *  Created on: Jun 22, 2013
 *      Author: amatzlia
 */

#ifndef ORDER_H_
#define ORDER_H_

#include "list.h"
#include "Album.h"

/**
 * A class used to represent an order in a record store, holding id and albums.
 */
class Order {
public:
	/**
	 * Creates a new order with the given id.
	 */
	explicit Order(int id);

	/**
	 * Adds an album to the order.
	 * If the order was already paid, mtm::ORDER_WAS_ALREADY_PAID exception
	 * is thrown.
	 * @param album the album to add to the order.
	 */
	void addAlbum(const Album& album);

	/**
	 * Removes an album or albums from the order which match the given album.
	 * If the order was already paid, mtm::ORDER_WAS_ALREADY_PAID exception
	 * is thrown.
	 * @param album the album to remove from the order.
	 */
	void removeAlbum(const Album& album);

	/**
	 * @return the id of the order.
	 */
	int getId() const;

	/**
	 * @return the current list of albums in the order (in the order of
	 *  addition to the order).
	 */
	const List<Album> getAlbums() const;

	/**
	 * Marks the order as paid, If the order was already paid,
	 * mtm::ORDER_WAS_ALREADY_PAID exception is thrown.
	 */
	void pay();

	/**
	 * @param customerId the id of the customer holding this order.
	 * @return a string describing the order, and the albums in it sorted by
	 * 	time of addition to the order.
	 */
	string getOrderReport(int customerId) const;

	/**
	 * A function object used to sort Order objects by id (ascending)
	 * and to find them by id, in a set of Orders.
	 */
	class SortById;

private:
	/**
	 * Verifies the order was not paid, if it was,
	 * mtm::ORDER_WAS_ALREADY_PAID exception is thrown.
	 */
	void verifyNotPaid();

	const int id;
	List<Album> albums;
	bool paid;
};

class Order::SortById {
public:
	bool operator()(Order orderA, Order orderB) const;
};

#endif /* ORDER_H_ */
